﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace LdCms.Web.Controllers.MVC.Community
{
    using LdCms.EF.DbModels;
    using LdCms.IBLL.Community;
    using LdCms.Common.Extension;
    using LdCms.Common.Utility;
    using LdCms.Common.Web;
    using LdCms.Web.Models;
    using LdCms.Web.Services;
    using LdCms.Common.Json;
    using LdCms.Web.Authorizes;
    /// <summary>
    /// 
    /// </summary>
    [AdminAuthorizeAttribute(Roles = "Admins")]
    public class CommunityThemeCollectController : BaseController
    {
        private readonly IBaseManager BaseManager;
        private readonly IVThemeCollectService VThemeCollectService;
        public CommunityThemeCollectController(IBaseManager BaseManager, IVThemeCollectService VThemeCollectService) : base(BaseManager)
        {
            this.BaseManager = BaseManager;
            this.VThemeCollectService = VThemeCollectService;
        }

        public override IActionResult Index()
        {
            return View();
        }

        public IActionResult List()
        {
            try
            {
                string funcId = PermissionEnum.CodeFormat((int)PermissionEnum.公告管理.公告信息.列表);
                if (!IsPermission(funcId)) { return ToPermission(funcId); }

                string startTime = GetQueryString("datemin");
                string endTime = GetQueryString("datemax");
                string keyword = GetQueryString("keyword");
                ViewData["DateMin"] = startTime;
                ViewData["DateMax"] = endTime;
                ViewData["Keyword"] = keyword;

                int total = 100;
                List<V_Community_ThemeCollect> lists = new List<V_Community_ThemeCollect>();
                string strKeyword = string.Format("{0}{1}", startTime, keyword);
                if (string.IsNullOrWhiteSpace(strKeyword))
                    lists = VThemeCollectService.GetThemeCollectTop(SystemID, CompanyID, total);
                else
                    lists = VThemeCollectService.SearchThemeCollect(SystemID, CompanyID, startTime, endTime, keyword, total);
                ViewData["Count"] = VThemeCollectService.CountThemeCollect(SystemID, CompanyID);
                return View(lists);
            }
            catch (Exception ex)
            {
                return ToError(ex.Message);
            }
        }




    }
}